import time
from datetime import datetime
import pyautogui as pg
import pyperclip as pc
from threading import Timer


def Message():
    return '无锡天明到常熟70吨'


def start():
    pg.hotkey('ctrl', 'alt', 'w')
    smile_pos = pg.locateCenterOnScreen('config/smile.png')
    pg.moveTo(smile_pos.x, smile_pos.y + 30)
    pg.leftClick()
    while True:
        try:

            x, y = pg.locateCenterOnScreen('config/tx.png')
            if x:
                begin = time.time()
                msg = Message()
                pc.copy(msg)
                pg.hotkey('ctrl', 'v')
                pg.hotkey('enter')

                pg.moveTo(x + 120, y + 30)
                pg.rightClick()
                del_pos = pg.locateCenterOnScreen('config/del.png')
                pg.moveTo(del_pos.x, del_pos.y)
                pg.leftClick()
                ok_pos = pg.locateCenterOnScreen('config/ok.png')
                pg.click(ok_pos.x, ok_pos.y)
                pg.leftClick()

                end = time.time()
                print(f'{datetime.now()}，{msg}\t耗时：%.2f S' % (end - begin))
                pg.moveTo(smile_pos.x, smile_pos.y + 30)
                pg.leftClick()


        except:
            pass


if __name__ == '__main__':
    timer = Timer(1, start)
    timer.start()
